import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:love_app/common/su.dart';
import 'package:love_app/pages/chat_page/chat.dart';
import 'package:love_app/routes/application.dart';
import 'package:love_app/routes/routes.dart';

class NotificationInit {
  final BuildContext context;

  NotificationInit(this.context);

  // 初始化
  void init(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) {
    var initializationSettingsAndroid =
        AndroidInitializationSettings('app_icon');
    // IOS初始化
    var initializationSettingsIOS = IOSInitializationSettings(
        onDidReceiveLocalNotification: onDidReceiveLocalNotification);
    var initializationSettings = InitializationSettings(
        initializationSettingsAndroid, initializationSettingsIOS);
    // 插件初始化
    flutterLocalNotificationsPlugin.initialize(initializationSettings,
        onSelectNotification: onSelectNotification);
  }

  Future<void> onDidReceiveLocalNotification(
      int id, String title, String body, String payload) async {
    // display a dialog with the notification details, tap ok to go to another page
    Su.suPrints("哈哈");
  }

  Future<void> onSelectNotification(String payload) async {
    if (payload != null) {
      // 聊天的， 跳转到聊天界面
      if (payload == 'message') {
        Application.navigatorKey.currentState
            .push(MaterialPageRoute(builder: (BuildContext context) {
          return ChatPage();
        }));
      }
    }
  }
}
